<template>
  <div class="table">
    <dv-scroll-board :config="config" style="width: 400px; height: 160px" />
  </div>
</template>
<script>
export default {
  props: {
    datalist: {
      type: Array,
    },
    siteNo: {
      type: String,
    },
  },
  mounted() {
    this.loadConfig();
  },
  computed: {
    listenAlarm() {
      return this.$store.state.message;
    },
  },
  watch: {
    datalist: {
      handler: function (val) {
        //推送告警消息
        this.$emit("alarmListChange", val);
        let data = [];
        this.datalist.some((item) => {
          if(item.category=="定温告警"){
            data.push([item.channel, item.lastTemp,item.differ, "一级",item.category]);
          }
          if(item.category=="升温告警"){
            data.push([item.channel, item.lastTemp,item.heatUpDiffer, "一级",item.category]);
          }
        });
        let config = { ...this.config };
        config.data = data;
        this.config = config;
      },
      deep: true,
    },
    //监听告警消息变化
    listenAlarm(nValue) {
      //判断是当前站点下的温度告警，更新dataList
      let alarmInfo = nValue;
      let alarmItem;
      if (
        alarmInfo["温度告警"] &&
        alarmInfo["温度告警"].siteNo == this.siteNo
      ) {
        alarmItem = alarmInfo["温度告警"];
      }
      if (
        alarmInfo["定温告警"] &&
        alarmInfo["定温告警"].siteNo == this.siteNo
      ) {
        alarmItem = alarmInfo["定温告警"];
      }
      if (
        alarmInfo["升温温告警"] &&
        alarmInfo["升温温告警"].siteNo == this.siteNo
      ) {
        alarmItem = alarmInfo["升温温告警"];
      }
      //判断是否已经存在告警列表中
      let alarmList = this.datalist.filter(
        (item) => item.channel == alarmItem.channel
      );
      if (alarmList.length < 1) {
        //添加到告警列表
        this.dataList.push(alarmItem);
      }
      if (
        alarmInfo["温度告警关闭"] &&
        alarmInfo["温度告警关闭"].siteNo == this.siteNo
      ) {
        alarmItem = alarmInfo["温度告警关闭"];
      }
      if (
        alarmInfo["升温告警关闭"] &&
        alarmInfo["升温告警关闭"].siteNo == this.siteNo
      ) {
        alarmItem = alarmInfo["升温告警关闭"];
      }
      if (
        alarmInfo["定温告警关闭"] &&
        alarmInfo["定温告警关闭"].siteNo == this.siteNo
      ) {
        alarmItem = alarmInfo["定温告警关闭"];
      }
       //判断是否存在告警列表中,存在则删除
        this.dataList.some((item, index) => {
          if (item.channel == alarmItem.channel) {
            this.dataList.splice(index, 1);
          }
        });
    },
  },
  data() {
    return {
      dataList: [],
      config: {
        header: ["通道号", "告警值", "差值","告警等级", "告警类型"],
        headerBGC: "#003366",
        align: ["center", "center"],
        oddRowBGC: "",
        evenRowBGC: "",
      },
    };
  },
  methods: {
    headClass() {
      return "background-color: transparent;color:#fff;font-weight:bold;";
    },
    loadConfig() {
      let data = [];
      this.datalist.some((item) => {
        if(item.category=="定温告警"){
            data.push([item.channel, item.lastTemp,item.differ, "一级",item.category]);
          }
          if(item.category=="升温告警"){
            data.push([item.channel, item.lastTemp,item.heatUpDiffer, "一级",item.category]);
          }
      });
      // let config = this.config
      this.config.data = data;
      // this.config = config;
    },
  },
  created() {},
  mounted() {},
};
</script>
<style scoped>
.table {
  position: absolute;
  right: 3%;
  margin: auto;
  bottom: 20%;
}
.el-table::before {
  left: 0;
  bottom: 0;
  width: 100%;
  height: 0px;
}
</style>
<style>
.customer-table th {
  border: none;
}
.customer-table td,
.customer-table th.is-leaf {
  border: none;
}
</style>
